package cn.z2huo.knowledge.designpattern.strategy.demo1;

/**
 * <p>
 *
 * @author z2huo
 */
class Calculator {

    private Strategy strategy;

    public Calculator() {
    }

    public Calculator(Strategy strategy) {
        this.strategy = strategy;
    }

    public void setStrategy(Strategy strategy) {
        this.strategy = strategy;
    }

    public int getResult(int a, int b) {
        return strategy.calculate(a, b);
    }

    public static void main(String[] args) {
        Calculator calculator = new Calculator();
        calculator.setStrategy(new Add());
        System.out.println(calculator.getResult(1, 2));

        calculator.setStrategy(new Subtraction());
        System.out.println(calculator.getResult(1, 2));
    }

}
